package com.javadude.gcm1;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService {

	@Override
	protected void onError(Context context, String errorId) {
		notify(context, "Error", errorId);
	}

	@Override
	protected void onMessage(Context context, Intent intent) {
		notify(context, "Message", intent.getStringExtra("stuff"));
	}

	@Override
	protected void onRegistered(Context context, String regId) {
		notify(context, "Registered", regId);
	}

	@Override
	protected void onUnregistered(Context context, String regId) {
		notify(context, "Unregistered", regId);
	}
	
	private int notificationId = 1;
	
	private void notify(Context context, String title, String message) {
		Notification notification =
			new NotificationCompat.Builder(this)
				.setNumber(10)
				.setTicker(title + ": " + message)
		        .setSmallIcon(android.R.drawable.ic_menu_directions)
		        .setContentTitle(title)
		        .setContentText(message)
				.build();
		
		NotificationManager notificationManager =
				(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		notificationManager.notify(notificationId++, notification);
	}
}
